package com.kla.power.mapper;

import com.kla.power.entity.InverterAcAmountEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 交流电 Mapper 接口
 * </p>
 *
 * @author WuZH
 * @since 2024-06-10
 */
@Mapper
public interface InverterAcAmountMapper extends BaseMapper<InverterAcAmountEntity> {

    @Select (value = "SELECT * FROM (SELECT * FROM inverter_ac_amount_info where inverterSn=#{inverterAcAmountEntity.inverterSn}) idi\n" +
            "where idi.createTime= " +
            "      (select max(id.createTime) from (select * from inverter_ac_amount_info where inverterSn=#{inverterAcAmountEntity.inverterSn}) id)")
    List<InverterAcAmountEntity> queryMaxDateList ( @Param ( "inverterAcAmountEntity" ) InverterAcAmountEntity inverterAcAmountEntity );

    /**
     * 查询逆变器历史数据
     * @param inverterAcAmountEntity
     * @return
     */
    @Select ( value = "<script>SELECT * FROM inverter_ac_amount_info iai " +
            "<trim prefix=\"WHERE\" prefixOverrides=\"and | or\">" +
            "<if test='inverterAcAmountEntity.inverterSn!=null'> AND iai.inverterSn=#{inverterAcAmountEntity.inverterSn} </if>" +
            " AND date_format(iai.createTime, '%Y-%m-%d') &gt;= date_format(#{inverterAcAmountEntity.startTime}, '%Y-%m-%d') AND date_format(iai.createTime, '%Y-%m-%d') &lt;= date_format(#{inverterAcAmountEntity.endTime}, '%Y-%m-%d') " +
            "</trim></script>")
    List<InverterAcAmountEntity> queryHistoryData ( @Param ( "inverterAcAmountEntity" ) InverterAcAmountEntity inverterAcAmountEntity );


}
